package client

import (
	"log"

	"gitee.com/xgotool/sqlite-logs-more/service/rootdb"
	"gitee.com/xiaoyutab/xgotool/https"
	"gitee.com/xiaoyutab/xgotool/optional/xcache"
	"gitee.com/xiaoyutab/xgotool/xstring"
)

// 获取设备详情信息
func GetDervice(remote string) *rootdb.Dervice {
	// 获取设备信息
	d := rootdb.Dervice{}
	mac := xstring.Mac()
	cache_key := xcache.Key("app.client.get.dervice", mac)
	if xcache.Exists(cache_key) {
		if err := xcache.GetStruct(cache_key, &d); err == nil {
			return &d
		}
	}
	if remote[0:4] == "http" {
		// 获取设备详情
		err := https.New(remote + "dervice.info").Param(xstring.Mac()).Post().JsonData(&d)
		if err != nil {
			log.Panicf("设备信息获取失败：%s", err.Error())
		}
	} else if remote[0:4] == "grpc" {
		// 如果是 grpc 协议
	}
	xcache.SetStruct(cache_key, d)
	return &d
}
